home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 525 < prev    next >
Internet Message Format  |  1996-08-06  |  2KB

  1. Path: tbj.dec.com!diamond
  2. From: diamond@tbj.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Bit-field sizes
  5. Date: 7 Mar 1996 03:50:05 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4hlmdd$266@usenet.pa.dec.com>
  8. References: <nzRPxQ9ytZZA084yn@csn.net>
  9. Reply-To: diamond@tbj.dec.com (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tbj.dec.com
  11.  
  12. In article <nzRPxQ9ytZZA084yn@csn.net>, thads@csn.net (Thad Smith) writes:
  13. >Can the size of a bit-field, measured in bits, exceed the size of an int?
  14.  
  15. A program that attempts to do it would have undefined behavior, but a kind
  16. implementation would define it by extension.  On the other hand, an unkind
  17. implementation could make all bit-fields exceed the size of an int.
  18.  
  19. >The description of bit-fields describes it as an integral type with a
  20. >(programmer-)specified number of bits, not specifically constrained in size.
  21.  
  22. Not quite.  ANSI Classic section 3.5.2.1, page 61 lines 15 to 17, has a
  23. Constraint requiring the specified width to fit in the number of bits in
  24. an ordinary object of compatible type.  So if the type is int then this
  25. constraint has the effect you say.  However, line 30 is a Semantic (not
  26. Constraint) restricting the size.  So, a non-strictly-conforming program
  27. can take advantage of an implementation extension without even getting a
  28. diagnostic.
  29.  
  30. >ANSI Classic section 3.2.1.1 says, however, that bit-fields are promoted
  31. >to either int or unsigned int.  This would seem to prohibit promoting a
  32. >large bit-field to a long.  If so, why was this constraint imposed?
  33.  
  34. Probably the same reason as most other defects in the standard :-)
  35.  
  36. >Secondly, is the storage unit within which bit-fields are allocated
  37. >constrained to be a single size or can it vary, depending on the size
  38. >of the bit fields?  I see nothing in the standard prohibiting
  39. >different size storage units for bit-fields.
  40.  
  41. Neither do I.  On the other hand, alignment is stated to be unspecified.
  42. Therefore the silence on variable sizing is ambiguous.
  43. --
  44.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  45. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  46. license, so I can drive in any lane I want, and no innocent victim gets to call
  47. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  48.